package hh;
import java.util.Scanner;
import static java.lang.Math.max;

public class project2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入数组的大小: ");
        int n = scanner.nextInt();
        int[] nums = new int[n];
        System.out.print("请输入数组的元素: ");
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }

        int maxSum = nums[0],s = 0;
        for(int i = 0; i < n;i++){
            s = max(s + nums[i],nums[i]);
            maxSum = max(maxSum,s);
        }
        System.out.println("具有最大和的连续子数组的和为: " + maxSum);
    }
}
//问题二：练习数值计算